from urllib.request import Request, urlopen
import requests
from random import randint
from tqdm import trange
import zipfile
from time import sleep
class update():
    def checkupdate(branch):
        headers = {'User-Agent': f'Mozilla/5.0 {randint(1000,9999)} Windows NT 10.0'}
        url = f'https://v.cssummer.top/pyqr/{branch}/v.html'
        url = Request(url, headers=headers)
        try:
            v=urlopen(url,timeout=15).read().decode('utf-8')
        except Exception as e:
            v=0
        return v
    def download(version):
        try:
            url=f'https://downloads.cssummer.top/pyqr/{version}.zip'
            print('开始下载,请稍等')
            mfile=requests.get(url, allow_redirects=True)
            open('new.zip','wb').write(mfile.content)
            print("下载完成")
            return 1
        except:
            return 0